#include <cmath>
#include "FeatureCompare.h"

double Dot_Product1(float* p1,float* p2, unsigned long N)
{
    float* q1=p1;
    float* q2=p2;
    double  sum=(double)0.0;
    unsigned long  i;

    for(i=0;i<N;i++)
        sum += (*q1++) * (*q2++);

    return sum;
}

void CompareVectors(const unsigned char *pTemplate1,const unsigned char *pTemplate2,
	double precomputation1,double precomputation2,double *pSimlarity)
{
	 int nDim1;
    int nDim2;

    nDim1 = 210;
    nDim2 = 210;

    double  dbSimilary = -2;
    dbSimilary =  Dot_Product1((float*)pTemplate1, (float*)pTemplate2, 210);
    dbSimilary /= sqrt(precomputation1 * precomputation2);
    *pSimlarity = (dbSimilary+1)/2.0;
}
void CompareVectors( unsigned char* pTemplate1, unsigned char* pTemplate2, double  *pSimlarity )
{
    int nDim1;
    int nDim2;

    nDim1 = 210;
    nDim2 = 210;

    double  dbSimilary = -2;
    dbSimilary =  Dot_Product1((float*)pTemplate1, (float*)pTemplate2, 210);
    dbSimilary /= sqrt(Dot_Product1((float*)pTemplate1, (float*)pTemplate1, nDim1) * Dot_Product1((float*)pTemplate2, (float*)pTemplate2, nDim1));
    *pSimlarity = (dbSimilary+1)/2.0;
}
